package com.itly.controller;

import com.itly.util.ApiResult;
import com.itly.entity.MultiQuestion;
import com.itly.service.MultiQuestionService;
import com.itly.util.ApiResultHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MultiQuestionController {
    private Logger logger = LoggerFactory.getLogger(MultiQuestionController.class);

    @Autowired
    private MultiQuestionService multiQuestionService;

    @PostMapping("MultiQuestion")
    public ApiResult MultiQuestion(@RequestBody MultiQuestion multiQuestion) {
        int i = multiQuestionService.addMultiQuestion(multiQuestion);
        if (i == 1) {
            logger.info("选择题添加成功");
            return ApiResultHandler.buildApiResult(200, "添加成功", i);
        }
        logger.info("选择题添加失败",multiQuestion);
        return ApiResultHandler.buildApiResult(400, "添加失败", i);
    }

    @GetMapping("multiQuestionId")
    public ApiResult multiQuestionId() {
        MultiQuestion multiQuestion = multiQuestionService.multiQuestionId();
        logger.info("通过id查询选择题");
        return ApiResultHandler.buildApiResult(200, "查询选择题Id", multiQuestion);
    }
}
